package com.sl.au.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.ChanceTrance;
import com.sl.au.entity.User;
import com.sl.au.repository.ChanceTranceRepository;
import com.sl.au.service.ChanceTranceService;

@Service("ChanceTranceService")
@Transactional
public class ChanceTranceServiceImpl extends BaseServiceImpl implements ChanceTranceService{

	@Autowired
	ChanceTranceRepository chanceTranceRepository;
	
	@Override
	public ChanceTranceRepository getRepository() {
		// TODO Auto-generated method stub
		return this.chanceTranceRepository;
	}

	@Override
	public List<ChanceTrance> getMyPage(int start, int length, Map<String, String> condition, String orderName, String dir) {
		Page<ChanceTrance> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");
		pages = chanceTranceRepository.findMyTrance(condition.get("chanceId"),condition.get("userId"), pageable);
		return pages.getContent();
	}

	@Override
	public List<ChanceTrance> getAllTrance(int start, int length, String chacneId, String orderName, String dir) {
		Page<ChanceTrance> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");
		pages = chanceTranceRepository.findAllTrance(chacneId, pageable);
		return pages.getContent();
	}

}
